/**
 * 协议
 * @return {[type]} [description]
 */
var name=window.sessionStorage.getItem('username');
var protocol_name=window.sessionStorage.getItem('protocolName');
function user_forms_save(){
	var request=new Object();
	request.username=name;
	request.protocol=protocol_name;
	var contents=[];
	if(document.getElementById("encrypt")){
		var field=new Object();
		var encrypt_items=$('#encrypt').children();
		field.type="encrypt";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	
	if(document.getElementById("auth")){
		var field=new Object();
		var encrypt_items=$('#auth').children();
		field.type="auth";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	if(document.getElementById("resubmit")){
		var field=new Object();
		var encrypt_items=$('#resubmit').children();
		field.type="resubmit";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	if(document.getElementById("defense")){
		var field=new Object();
		var encrypt_items=$('#defense').children();
		field.type="defense";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	if(document.getElementById("field_length")){
		var field=new Object();
		var encrypt_items=$('#field_length').children();
		field.type="field_length";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	if(document.getElementById("extend")){
		var field=new Object();
		var encrypt_items=$('#extend').children();
		field.type="extend";
		field.name=encrypt_items[0].value;
		field.data_type=encrypt_items[1].value;
		field.length=encrypt_items[2].value;
		field.meaning=encrypt_items[3].value;
		field.position_start=encrypt_items[4].value;
		field.position_end=encrypt_items[5].value;
		field.information=encrypt_items[6].value;
		contents.push(field);
	}
	request.content=contents;
	var jsonStr=JSON.stringify(request);
	return jsonStr;
}


function save(){
	var json=user_forms_save();
	//alert(json);
	$.ajax({
        url:'http://localhost:8080/saveFieldDesigns',
        type:'POST',
        data:{'json':json},
        dataType:'json',
        success:function (data) {
        	alert(data.meta.message);
        }
    });
}

function encrypt(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','encrypt');
	one_item.addClass('one_item');
	one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}
function auth(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','auth');
	one_item.addClass('one_item');
	one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}
function resubmit(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','resubmit');
	one_item.addClass('one_item');
    one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}
function defense(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','defense');
	one_item.addClass('one_item');
	one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}
function length(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','field_length');
	one_item.addClass('one_item');
	one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}
function extend(){
	var holder=$('#holder_of_items');
	var one_item=$('<div></div>');  
	one_item.attr('id','extend');
	one_item.addClass('one_item');
	one_item.append('<input class="items" id="name" /><input class="items" id="data_type" /><input class="items" id="length" /><input class="items" id="meaning"/><input class="items" id="position_start" /><input class="items" id="position_end" /><input class="items" id="information" />');
	holder.append(one_item);
}

